package com.yaorange.api;

import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.nongjt.domain.NjtArea;
import com.yaorange.nongjt.service.INjtAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "区域管理", tags = "区域管理")
@RestController
@RequestMapping("/api/area")
public class NjtAreaAPI {

    @Autowired
    private INjtAreaService njtAreaService;

    /**
     * 获取所有根节点
     *
     * @return
     */
    @ApiOperation("获取所有根节点")
    @GetMapping("/queryListRoot")
    public AjaxResult queryListRoot() {
        List<List<NjtArea>> columns = njtAreaService.getDefaultListRoot();
        return AjaxResult.success(columns);
    }

    /**
     * 根据父编码查询所有子区域
     *
     * @param parentCode 父编码
     * @return 该地区下的所有子地区
     */
    @ApiOperation("根据父编码查询所有子区域")
    @GetMapping("/queryChildrenByParentCode")
    @ApiImplicitParam(name = "parentCode", value = "父编码", required = true, dataType = "String")
    public AjaxResult queryChildrenByParentCode(@RequestParam("parentCode") String parentCode) {
        List<NjtArea> areaList = njtAreaService.getChildrenByParentCode(parentCode, false);
        return AjaxResult.success(areaList);
    }
}